#include <iostream>
using namespace std;
const int N = 105;
int n, m, ans;
int arr[N][N];
char c; 
void def(int i, int j){
	if (arr[i][j] == 0) return;
	arr[i][j] = 0;
	def(i, j + 1);
	def(i, j - 1);
	def(i + 1, j);
	def(i - 1, j);
}
int main(){
	cin >> n >> m;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			cin >> c;
			arr[i][j] = c - '0';
		}
	}
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			if (arr[i][j] == 1){
				ans++;
				def(i, j);
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}
